﻿@using PagedList.Mvc
@model PagedList.IPagedList<CubicFWNet.Data.ViewModal.ProductView>
@{
    ViewBag.Title = "产品查询";
    //var type = ViewBag.Type;
    var productName = ViewBag.ProductName;
    var categorys = ViewBag.CategoryList as List<CubicFWNet.Data.Models.Category>;
    var module = ViewBag.UserModules as List<CubicFWNet.Data.Models.Module>;
}
<section class="content-header">
    <h1>
        产品查询
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">产品查询</li>
    </ol>
</section>
<section class="content">
    <div class="form-horizontal">
        <div class="box box-solid">
            <div class="box-nav clearfix">
                @*<div class="col-sm-12">
                        <button type="button" class="btn btn-primary" onclick="Select();" title="查询"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
                        <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                    </div>*@
                <form action="@Url.Action("Index", "Product")" method="post">
                    <div class="col-sm-12">
                        <div class="col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right">产品名称</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="ProductName" placeholder="请输入产品名称/产品编号" name="ProductName" value="@ViewBag.ProductName" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for=""> 宽 </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="Width" name="Width" placeholder="请输入产品宽" value="@ViewBag.Width" />
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right" for=""> 长 </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="Length" name="Length" placeholder="请输入长" value="@ViewBag.Length" />
                            </div>
                        </div>
                        @*<div class="col-sm-4">
                                <label class="col-sm-4 control-label no-padding-right">产品分类</label>
                                <div class="col-sm-8" style="padding-top: 7px;">
                                    @if (ViewBag.Type == 0)
                                    {
                                        <input type="radio" name="Type" value="0" checked /><label>全部</label>
                                        <input type="radio" name="Type" value="1" /><label>成品</label>
                                        <input type="radio" name="Type" value="2" /><label>原材</label>
                                    }
                                    else if (ViewBag.Type == 1)
                                    {
                                        <input type="radio" name="Type" value="0" /><label>全部</label>
                                        <input type="radio" name="Type" value="1" checked /><label>成品</label>
                                        <input type="radio" name="Type" value="2" /><label>原材</label>
                                    }
                                    else
                                    {
                                        <input type="radio" name="Type" value="0" /><label>全部</label>
                                        <input type="radio" name="Type" value="1" /><label>成品</label>
                                        <input type="radio" name="Type" value="2" checked /><label>原材</label>
                                    }
                                </div>
                            </div>*@
                    </div>
                    <div class="col-sm-12" style="margin-top:10px;">
                        <div class="col-sm-4">
                            <label class="col-sm-4 control-label no-padding-right">产品类型</label>
                            <div class="col-sm-8">
                                <select class="form-control form-control-static" name="categoryid">
                                    @if (categorys != null)
                                    {
                                        foreach (var item in categorys)
                                        {
                                            if (ViewBag.CategoryId == item.Id)
                                            {
                                                <option value="@item.Id" selected>@item.Name</option>
                                            }
                                            else
                                            {
                                                <option value="@item.Id">@item.Name</option>
                                            }
                                        }
                                    }
                                </select>
                                @*<input type="text" class="form-control" id="ProductNum" name="ProductNum" value="@ViewBag.ProductNum" />*@
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <button type="submit" class="btn btn-primary">查询</button>
                            <a class="btn btn-default" onclick="javascript: window.location.reload();" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="box box-solid">
            <div class="box-body">
                <table class="footable table table-stripped table-bordered table-hover" id="footable" data-page-size="20" data-filter=#filter>
                    <thead>
                        <tr>
                            <th data-sort-ignore="true">
                                名称
                            </th>
                            <th data-sort-ignore="true">
                                编号
                            </th>
                            @if (module.Any(a => a.Url != null && a.Url.Contains("/Product/Price")))
                            {
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    内部价格
                                </th>
                            }
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                宽*长(mm)
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                类型
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                单位
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                规格
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                执行部门
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                创建时间
                            </th>
                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                备注
                            </th>
                            @if (module.Any(a => a.Url != null && a.Url.Contains("/Product/Edit")))
                            {
                                <th data-sort-ignore="true">
                                    操作
                                </th>
                            }
                            </tr>
                    </thead>
                    <tbody>
                        @if (null != Model)
                        {
                            foreach (var item in Model)
                            {
                                if (item.Status != -2)
                                {
                                    <tr>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Name)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Number)
                                        </td>
                                        @if (module.Any(a => a.Url != null && a.Url.Contains("/Product/Price")))
                                        {
                                            <td>
                                                @item.Price.ToString("#0.0000")
                                            </td>
                                        }
                                        <td>
                                            @item.SizeWidth * @item.SizeLenth
                                        </td>
                                        @*<td>
                                                @if (item.Type == 1)
                                                {
                                                    <span>成品</span>
                                                }
                                                else if (item.Type == 2)
                                                {
                                                    <span>原料</span>
                                                }
                                            </td>*@
                                        <td>
                                            @Html.DisplayFor(modelItem => item.CategoryName)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Unit)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Format)
                                        </td>
                                        <td>
                                            @if (item.ExecuteDepartment == 1)
                                            {
                                                <span> 工厂 </span>
                                            }
                                            else if (item.ExecuteDepartment == 2)
                                            {
                                                <span> 采购 </span>
                                            }
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.CreateTime)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Memo)
                                        </td>
                                        @if (module.Any(a => a.Url != null && a.Url.Contains("/Product/Edit")))
                                        {
                                            <td>
                                                <span class="btn bg-blue btn-sm" onclick="ShowModal('@item.Id')">查看</span>&nbsp;&nbsp;&nbsp;
                                                <a class="btn bg-blue btn-sm" href="@Url.Action("Edit", "Product", new { PID = item.Id })">编辑</a>
                                                <button class="btn btn-warning btn-sm" cursor: pointer;" onclick="EditDlg('@item.Id','@item.Name',@Convert.ToInt32(item.Price))">修改价格</button>
                                            </td>
                                        }
                                    </tr>
                                }
                            }
                        }
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="7">
                                每页 @Model.PageSize 条记录，共 @Model.PageCount 页，当前第 @Model.PageNumber 页
                                @Html.PagedListPager(Model, page => Url.Action("Index", new { page, productName, categoryId = ViewBag.CategoryId, width = ViewBag.Width, length = ViewBag.Length }))
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</section>
<div class="modal" id="EditDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="title"></h4>
            </div>
            <form class="form-horizontal" id="EditFrm" method="post">
                <div class="modal-body">
                    <input type="hidden" id="PID" name="PID" />
                    <input type="hidden" id="StorageId" name="StorageId" />
                    <div class="form-group">
                        <label class="col-sm-3 control-label">名称</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" readonly id="Name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="Price" class="col-sm-3 control-label"><span class="text-danger">*</span>&nbsp;&nbsp;内部价格</label>
                        <div class="col-sm-8">
                            <input type="number" required class="form-control" id="Price" name="Price" min="0" />
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <div type="submit" onclick="edit()" class="btn btn-primary">确认</div>
                </div>
            </form>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        $(document).ready(function () {
            $('#footable').footable();
        });
          function EditDlg(pid, name,amount) {
            $('#EditDlg').find("#PID").val(pid);
            $('#EditDlg').find("#Name").val(name);
            $('#EditDlg').find("#Price").val(amount);
            $('#EditDlg').modal();
        }
        function edit() {
            var Price = $('#EditDlg').find("#Price").val().trim();
            if (Price == "") {
                $.modalAlert("请输入内部价格", "warning");
                return false;
            }
            //出入库
            var form = document.getElementById('EditFrm');
            var formData = new FormData(form);
            $.ajax({
                url: "@Url.Action("EditProductPrice", "Product")" ,
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res != "") {
                        layer.msg(res, {
                          icon: 1,
                          time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                         $.reload();
                        });
                    }
                }
            });
        }
        function ShowModal(id) {
            var options = {
                id: null,
                title: '产品信息',
                width: "90%",
                height: "90%",
                url: "../Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }
    </script>
}